package cn.ad.server.domain.ad.vo;

import com.baidu.bjf.remoting.protobuf.FieldType;
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;

import java.text.SimpleDateFormat;
import java.util.*;

public class StrategyGroupVO {

	/**
	 * 
	 */
	// private static final long serialVersionUID = 1745837993170586747L;

	/**
	 * json包含id, speedMode, dayBudget, status, usableHour, dayTargetMap,
	 * usableHourKey, usableHourValue
	 */

	@Protobuf(order = 1)
	private long id;

	@Protobuf(order = 2)
	private int speedMode;

	@Protobuf(order = 3)
	private double dayBudget;

	@Protobuf(order = 4)
	private int status;

	@Protobuf(order = 5, fieldType = FieldType.MAP)
	private Map<String, Integer> usableHour = new HashMap<>();

	@Protobuf(order = 6, fieldType = FieldType.MAP)
	private Map<String, Integer> dayTargetMap = new HashMap<>();

	@Protobuf(order = 7, fieldType = FieldType.STRING)
	private List<String> usableHourKey = new ArrayList<>();

	@Protobuf(order = 8, fieldType = FieldType.INT32)
	private List<Integer> usableHourValue = new ArrayList<>();

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int getSpeedMode() {
		return speedMode;
	}

	public void setSpeedMode(int speedMode) {
		this.speedMode = speedMode;
	}

	public double getDayBudget() {
		return dayBudget;
	}

	public void setDayBudget(double dayBudget) {
		this.dayBudget = dayBudget;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public Map<String, Integer> getUsableHour() {
		return usableHour;
	}

	public void setUsableHour(Map<String, Integer> usableHour) {
		this.usableHour = usableHour;
	}

	private void usablehourPut(String key, Integer total) {
		if (usableHour == null) {
			usableHour = new HashMap<>();
		}
		usableHour.put(key, total);
	}

	public void putUsablehour(Date key, Integer total) {
		String strKey = format.format(key);
		usablehourPut(strKey, total);
	}

	/**
	 * 根据 date 得到当天可用的小时数
	 * 
	 * @param key
	 * @return
	 */
	public Integer getUsablehour(Date key) {

		String strKey = format.format(key);

		if (usableHour == null) {
			return null;
		}
		return usableHour.get(strKey);
	}

	private final static SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");

	public List<String> getUsableHourKey() {
		return usableHourKey;
	}

	public void setUsableHourKey(List<String> usableHourKey) {
		this.usableHourKey = usableHourKey;
	}

	public List<Integer> getUsableHourValue() {
		return usableHourValue;
	}

	public void setUsableHourValue(List<Integer> usableHourValue) {
		this.usableHourValue = usableHourValue;
	}

	public void addUsableHour(Date key, Integer total) {
		String strKey = format.format(key);
		usableHourKey.add(strKey);
		usableHourValue.add(total);
	}

	public Integer getUsableHour(Date key) {
		String strKey = format.format(key);
		for (int i = 0; i < usableHourKey.size(); i++) {
			if (strKey.equals(usableHourKey.get(i))) {
				return usableHourValue.get(i);
			}
		}
		return null;
	}

	public Map<String, Integer> getDayTargetMap() {
		return dayTargetMap;
	}

	public void setDayTargetMap(Map<String, Integer> dayTargetMap) {
		this.dayTargetMap = dayTargetMap;
	}

	public void putDayTargetMap(Date key, Integer total) {
		String strKey = format.format(key);
		dayTargetMapPut(strKey, total);
	}

	private void dayTargetMapPut(String key, Integer total) {
		if (dayTargetMap == null) {
			dayTargetMap = new HashMap<>();
		}
		dayTargetMap.put(key, total);
	}

	/**
	 * 根据 date 得到当天的定向。(1110110101011)
	 * 
	 * @param key
	 * @return
	 */
	public Integer getDayTargetMap(Date key) {
		String strKey = format.format(key);

		if (dayTargetMap == null) {
			return null;
		}
		return dayTargetMap.get(strKey);
	}
}